<style>
	.chaphb {
		color: #20a53a;
		font-size: 14px;
		left: 14px;
		position: relative;
		top: 62px;
	}
	.testServer{
		padding:15px;
	}
	.ts-head{
		height:130px;
		position:relative;
	}
	.ts-h-score{
		float: left;
		height: 62px;
		margin: 30px 0 0 40px;
		display:none;
	}
	.old-score {
		color: #888;
		font-size: 14px;
		left: 50%;
		margin-left: -100px;
		position: absolute;
		text-align: center;
		top: 90px;
		width: 200px;
	}
	.ts-stamper{
		border-radius: 45px;
		height: 90px;
		left: 280px;
		position: absolute;
		top: 20px;
		width: 90px;
		transform:rotate(-30deg);
	}
	.ts-h-s-img{
		background-repeat:no-repeat;
		background-size:90px auto;
		background-position:center center;
		height:62px;
		width:96px;
		float:left;
	}
	.ts-h-s-img1{
		background-image:url("");
	}
	.ts-h-s-img2{
		background-image:url("");
	}
	.ts-h-s-img3{
		background-image:url("");
	}
	.ts-h-s-imging{
		background-image:url("");
	}
	.ts-h-s-num{
		color: #20a53a;
		float: left;
		font-size: 20px;
		margin-left: 30px;
	}
	.ts-h-s-num span{
		font-size: 22px;
		line-height: 60px;
		margin-right: 8px;	
	}
	.ts-h-s-num span img{
		margin-left:10px;
	}
	.ts-btn{
		border: 1px solid #cacad9;
		background-color:#fff;
		border-radius: 3px;
		height: 40px;
		line-height: 40px;
		color:#666;
		position: absolute;
		left: 265px;
		text-align: center;
		top: 39px;
		width: 140px;
		cursor:pointer;
	}
	.ts-btn-start{
		border: 1px solid #20a53a;
		background-color:#20a53a;
		left:265px;
		color:#fff;
	}
	.ts-btn-start:hover{
		background-color:#10952a;
	}
	.ts-btn-reset:hover,.btphb:hover{
		border: 1px solid #20a53a;
		color:#20a53a;
	}
	.ts-info{
		height:30px;
		color:#666;
		border-bottom:#CACAD9 1px solid;
		padding-left:40px;
		font-size:14px;
	}
	.ts-info font{
		font-size:16px;
		font-weight:bold;
		margin-right:3px;
		color:#20a53a;
	}
	.ts-info a{
	    color: #20a53a;
	    margin-left: 20px;
	}
	.ts-info img{
		margin-left:6px;
	}
	.ts-content{
		float: left;
		padding: 40px 0;
		width: 100%;
	}
	.ts-c-box{
		width:33%;
		float:left;
		text-align:center;
		position:relative;
	}
	.ts-c-b-score{
		font-size:16px;
		height:30px;
		color:#868686;
	}
	.ts-c-b-img{
		border:#B9B9C8 1px solid;
		height:90px;
		width:90px;
		border-radius:45px;
		margin:0 auto;
		background-repeat:no-repeat;
		background-position:center center;
		position:relative;
		z-index:1;
	}
	.ts-cpu-ing .ts-c-b-img{
		border:0 none;
	}
	.ts-c-b-name{
		color:#888;
		font-size:16px;
		line-height:40px;
	}
	.ts-c-b-info{
		color:#aaa;
	}

	@-webkit-keyframes rotation{
		from {-webkit-transform: rotate(0deg);}
		to {-webkit-transform: rotate(360deg);}
	}
	.ts-box-rotate{
		background:url("") no-repeat;
		border-radius: 50px;
		height: 100px;
		left: 61px;
		position: absolute;
		top: 25px;
		width: 100px;
		z-index: 0;
		animation: rotation 2s linear infinite;
		-moz-animation: rotation 2s linear infinite;
		-webkit-animation: rotation 2s linear infinite;
		-o-animation: rotation 2s linear infinite;
	}

	.ts-cpu .ts-c-b-img{
		background-image:url("");
	}
	.ts-mem .ts-c-b-img{
		background-image:url("");
	}
	.ts-disk .ts-c-b-img{
		background-image:url("");
	}

	.ts-cpu-ing .ts-c-b-img{
		background-image:url("");
		border:none;
	}
	.ts-mem-ing .ts-c-b-img{
		background-image:url("");
		border:none;
	}
	.ts-disk-ing .ts-c-b-img{
		background-image:url("");
		border:none;
	}
	.ts-cpu-over .ts-c-b-img{
		background-image:url("");
		border-color:#20a53a;
	}
	.ts-mem-over .ts-c-b-img{
		background-image:url("");
		border-color:#20a53a;
	}
	.ts-disk-over .ts-c-b-img{
		background-image:url("");
		border-color:#20a53a;
	}
</style>
<div class="testServer">
	<div class="ts-head">
		<div class="ts-h-score">
			<div class="ts-h-s-img ts-h-s-imging"><a class="chaphb" href="https://www.bt.cn/score" target="_blank">查看排行榜</a></div>
			<div class="ts-h-s-num"><span>正在跑分中<img src="/static/img/ings.gif"></span></div>
			<div class="ts-stamper"></div>
		</div>
		<div class="ts-btn ts-btn-start" onclick="startTest();">开始跑分</div>
		<div class="old-score"><a href="javascript:btphb();" class="btlink">我的排名</a></div>
	</div>
	<div class="ts-info">公式：1万次整数+2万次浮点+1亿位圆周率+1万次排序 +((磁盘读+磁盘写)*IO速度)+内存容量</div>
	<div class="ts-content">
		<div class="ts-c-box ts-cpu">
			<div class="ts-c-b-score"></div>
			<div class="ts-c-b-img"></div>
			<div class="ts-c-b-name">CPU</div>
			<div class="ts-c-b-info">cpu运算能力</div>
		</div>
		<div class="ts-c-box ts-disk">
			<div class="ts-c-b-score"></div>
			<div class="ts-c-b-img"></div>
			<div class="ts-c-b-name">磁盘</div>
			<div class="ts-c-b-info">磁盘读写能力</div>
		</div>
		<div class="ts-c-box ts-mem">
			<div class="ts-c-b-score"></div>
			<div class="ts-c-b-img"></div>
			<div class="ts-c-b-name">内存</div>
			<div class="ts-c-b-info">内存容量</div>
		</div>
	</div>
</div>
<script type="javascript/text">
	(function($){
	$.fn.stamper = function(options) {
		var opts = $.extend({
			scale : 5, // 图片初始大小，在原始图片大小上的倍数
			speed : 600 // 动画持续时间，单位毫秒
		}, options);
		
		this.each(function(index) {
			var target = $(this);
			var imgId = target.attr("data-stamper-img-id");
			if (!imgId) {
				imgId = "jquery_stamper_img_" + (new Date().getTime()) + "_" + index;
				target.attr("data-stamper-img-id", imgId);
			}
			var img = new Image();
			img.src = opts.image;
			img.onload = function() {
				var orgiCoor = getImageCoordinate(target, img);
				var initCoor = getStartCoordinate(target, img, opts.scale);
				var imgObj = getImageElement(imgId).attr("src", img.src)
					.css({
						position : "absolute",
						opacity : "0",
						left : "-106px",
						top : "-116px",
						width : initCoor.w + "px",
						height : initCoor.h + "px"
					})
					.show()
					.animate({
						opacity : "1",
						left : "0px",
						top : "0px",
						width : orgiCoor.w + "px",
						height : orgiCoor.h + "px"
					}, opts.speed, opts.complete);
			};
		});
	};
	
	/** 获取img的DOM对象 **/
	function getImageElement(id) {
		var img = $("#" + id);
		if (img.length == 0) {
			return $("<img id=\"" + id + "\" />").appendTo($(".ts-stamper")).hide();
		} else {
			return img.hide();
		}
	}
	
	/** 获取图片的落脚坐标点（以当前元素为基准）和尺寸信息，格式：{x:10,y:20,h:100,w:200} **/
	function getImageCoordinate(target, image) {
		var offset = $(target).offset();
		var cx = offset.left + $(target).width()/2;
		var cy = offset.top + $(target).height()/2;
		return {
			x : cx - image.width/2,
			y : cy - image.height/2,
			w : image.width,
			h : image.height
		};
	}
	
	/** 给定倍数（multiple）获取图片的开始位置和大小信息，格式：{x:10,y:20,h:100,w:200} **/
	function getStartCoordinate(target, image, multiple) {
		var offset = $(target).offset();
		var cx = offset.left + $(target).width()/2;
		var cy = offset.top + $(target).height()/2;
		var width = image.width * multiple;
		var height = image.height * multiple;
		return {
			x : cx - width/2,
			y : cy - height/2,
			w : width,
			h : height
		};
	}
})(jQuery);

	function startTest(){
		var name = $(".ts-btn").text();
		switch(name){
			case '开始跑分':
				startTestServer(name);
				break;
			case '正在跑分':
				stopTestServer();
				break;
			case '重新跑分':
				startTestServer(name);
				break;
		}
	}
	if(getCookie("#Total") >0){
		$(".old-score").html("上次跑分："+getCookie("#Total") + ' 分 <a href="javascript:btphb();" class="btlink" style="margin-left:10px">我的排名</a>').show();
	}

	function startTestServer(name){
		layer.confirm('测试过程可能需要几分钟时间且占用大量服务器资源，继续吗？',{title:'性能测试',closeBtn:2},function(){
				layer.closeAll('dialog');
				if(name == "重新跑分"){
					$(".btphb").remove();
					$(".ts-content").find(".ts-box-rotate").remove();
					$(".ts-h-s-num").html('<span>正在跑分中<img src="/static/img/ings.gif"></span>');
					$(".ts-btn-reset").removeAttr("onclick").width(140);
					$(".ts-cpu-over").removeClass("ts-cpu-over");
					$(".ts-disk-over").removeClass("ts-disk-over");
					$(".ts-mem-over").removeClass("ts-mem-over");
					$(".ts-h-s-img").removeClass("ts-h-s-img1");
					$(".ts-h-s-img").removeClass("ts-h-s-img2");
					$(".ts-h-s-img").removeClass("ts-h-s-img3");
					$(".ts-h-s-img").addClass("ts-h-s-imging");
					$(".ts-stamper").html("");
				}
				$(".old-score").fadeOut();
				$(".ts-btn").removeClass("ts-btn-start").text("正在跑分").animate({"left":"490px"});
				$(".ts-h-score").fadeIn();
				$(".ts-cpu").addClass("ts-cpu-ing").append("<div class='ts-box-rotate'></div>");
				$(".ts-info").html("正在测试整数运算性能[1万次]<img src='/static/img/ing.gif'>");
				var cpuscore = 0;
				$.get('/plugin?action=a&name=score&s=testCpu&type=1',function(rint){
					cpuscore += rint.score;
					$(".ts-info").html("正在测试浮点运算性能[2万次]<img src='/static/img/ing.gif'>");
					$.get('/plugin?action=a&name=score&s=testCpu&type=2',function(rfloat){
						cpuscore += rfloat.score;
						$(".ts-info").html("正在测试圆周率运算[1亿位]<img src='/static/img/ing.gif'>");
						$.get('/plugin?action=a&name=score&s=testCpu&type=3',function(rpi){
							cpuscore += rpi.score;
							$(".ts-info").html("正在测试二叉树排序算法[1万次]<img src='/static/img/ing.gif'>");
							$.get('/plugin?action=a&name=score&s=testCpu&type=4',function(r1){
								r1.score += cpuscore;
								$(".ts-cpu").removeClass("ts-cpu-ing").addClass("ts-cpu-over").find(".ts-box-rotate").remove();
								$(".ts-disk").addClass("ts-disk-ing").append("<div class='ts-box-rotate'></div>");
								$(".ts-cpu .ts-c-b-score").html(r1.score);
								$(".ts-cpu .ts-c-b-info").html(r1.cpuType + ' ' +r1.cpuCount + ' 核心');
								//$("#cpuType").html('型号:' + r1.cpuType);
								setCookie('cpuTotal',r1.score);
								setCookie('cpuCount',r1.cpuCount + ' 核心');
								setCookie('cpuType','型号:' + r1.cpuType);
								$(".ts-info").html("正在测试磁盘性能<img src='/static/img/ing.gif'>");
								$.get('/plugin?action=a&name=score&s=testDisk',function(r2){
									$(".ts-disk").removeClass("ts-disk-ing").addClass("ts-disk-over").find(".ts-box-rotate").remove();
									$(".ts-mem").addClass("ts-mem-ing").append("<div class='ts-box-rotate'></div>");
									$(".ts-disk .ts-c-b-score").html(r2.score);
									$(".ts-disk .ts-c-b-info").html('读: ' + r2.read + ' MB，写: ' + r2.write + ' MB');
									setCookie('diskTotal',r2.score);
									setCookie('diskRead','Read: ' + r2.read + ' MB');
									setCookie('diskWrite','Write: ' + r2.write + ' MB');
									$(".ts-info").html("正在测试内存<img src='/static/img/ing.gif'>");
									$.get('/plugin?action=a&name=score&s=testMem','',function(r3){
										$(".ts-mem").removeClass("ts-mem-ing").addClass("ts-mem-over").find(".ts-box-rotate").remove();
										$(".ts-mem .ts-c-b-score").html(parseInt(r3));
										$(".ts-mem .ts-c-b-info").html( r3 + ' MB');
										var total = r1.score+r2.score+ parseInt(r3);
										$(".ts-h-s-num span").html(total + ' 分').css({"font-size":"40px"});
										setCookie("#memTotal",r3 + ' MB');
										setCookie("#Total",total);
										$(".ts-btn").addClass("ts-btn-reset").text("重新跑分").css({"left":"550px","width":"80px"}).attr("onclick","startTestServer('重新跑分')");
										$(".ts-h-score").after('<div class="ts-btn btphb" onclick="btphb()" style="width: 80px; left: 450px;">我的排名</div>');
										if(total<2500){
											$(".ts-h-s-img").removeClass("ts-h-s-imging").addClass("ts-h-s-img1");
											scoreIco("1");
										}
										if(total>2500 && total<10000){
											$(".ts-h-s-img").removeClass("ts-h-s-imging").addClass("ts-h-s-img2");
											scoreIco("2");
										}
										if(total > 10000){
											$(".ts-h-s-img").removeClass("ts-h-s-imging").addClass("ts-h-s-img3");
											scoreIco("3");
										}
										
										var data = "soc="+total;
										$.get("/ajax?action=GetAd&name=zun",data,function(rad){
											$(".ts-info").html(rad);
										});
									});
								});
							});
						});
					});
				});
			});
	}
	function stopTestServer(){
		/*
		$(".ts-btn").addClass("ts-btn-start").removeClass("ts-btn-reset").text("开始测试").animate({"left":"233px"});
		$(".ts-h-score").fadeOut();
		$(".ts-info").html("跑分计算规则为：通过计算cpu运算能力，计算内存吞吐能力，计算磁盘读写能力");
		*/
		//layer.msg("测试中，不能停止",{shade:0.3});
		return false;
	}
	function scoreIco(ico) {
		var img = '';
		switch(ico){
			case "1":
				img = '';
				break;
			case "2":
				img = '';
				break;
			case "3":
				img = '';
				break;
		}
		$(".ts-stamper").stamper({
			image : img,
			scale : 3,
			speed : 300,
			complete : function() {
				//alert("完成啦~~~~");
			}
		})
	}
	
	function GetScore(){
		$.get('/plugin?action=a&name=score&s=GetScore',function(rdata){
			
		});
	}
	GetScore();
	//我的排名
	function btphb(){
		$.get("/ssl?action=GetUserInfo",function(rdata){
				if(rdata.status){
					var loadT = layer.msg("获取列表..",{icon:16,time:0});
					var tr = "";
					$.get("/plugin?action=a&name=score&s=GetScore",function(pm){
						layer.close(loadT);
						if(pm.status){
							for(var i=0; i<pm.data.length; i++){
								tr += '<tr><td>'+pm.data[i].address+'</td><td>'+pm.data[i].core+'核 | '+pm.data[i].memory+'MB | 读'+pm.data[i].disk.split(",")[0]+'MB/s | 写'+pm.data[i].disk.split(",")[1]+'MB/s</td><td>'+pm.data[i].virt+'</td><td>'+pm.data[i].isp+'</td><td>'+pm.data[i].total_score+'</td><td class="text-right"><a href="https://www.bt.cn/score?address='+pm.data[i].address+'" class="btlink" target="_blank">查看排名</a></td></tr>';
							}
							layer.open({
								type: 1,
								area: "700px",
								title: "我的服务器跑分",
								closeBtn: 2,
								shadeClose: false,
								content: '<div class="bt-form pd15" style="max-height:450px;overflow:auto">\
											<div class="divtable">\
												<table class="table table-hover">\
													<thead><tr><th>服务器IP</th><th>配置</th><th>平台</th><th>服务商</th><th>跑分</th><th class="text-right" width="80px">查看排名</th></tr></thead>\
													<tbody>'+tr+'</tbody>\
												</table>\
											</div>\
										</div>'
								
							})
						}
						
					})
				}
				else{
					bindBTName(2,'b');
				}
			});
	}
	//绑定修改宝塔账号
	function bindBTName(a,type){
		var titleName = "绑定宝塔账号";
		if(type == "b"){
			btn = "<button type='button' class='btn btn-success btn-sm' onclick=\"bindBTName(1,'b')\">绑定</button>";
		}
		if(a == 1) {
			p1 = $("#p1").val();
			p2 = $("#p2").val();
			$.post(" /ssl?action=GetToken", "username=" + p1 + "&password=" + p2, function(b) {
				if(b.status) {
					$(".btn-bw").click();
					layer.msg(b.msg, {
						icon: 1
					});
					$.get("/plugin?action=a&name=score&s=SubmitScore",function(p){
						//layer.msg(p.msg,{icon:p.status?1:2});
					});
					btphb();
				} else {
					layer.msg(b.msg, {
						icon: 2
					})
				}
			});
			return
		}
		var bindw = layer.open({
			type: 1,
			area: "290px",
			title: titleName,
			closeBtn: 2,
			shift: 5,
			shadeClose: false,
			content: "<div class='bt-form pd20 pb55'><div class='line'><span class='tname'>账号</span><div class='info-r'><input class='bt-input-text' type='text' name='username' id='p1' value='' placeholder='宝塔官网账户' style='width:100%'/></div></div><div class='line'><span class='tname'>密码</span><div class='info-r'><input class='bt-input-text' type='password' name='password' id='p2' value='' placeholder='宝塔官网密码' style='width:100%'/></div></div><div class='line text-right'><a class='c8' href='https://www.bt.cn/register.html' target='_blank'>注册宝塔账号</a></div><div class='bt-form-submit-btn'><button type='button' class='btn btn-danger btn-sm btn-bw'>取消</button> "+btn+"</div></div>"
		})
		$(".btn-bw").click(function(){
			layer.close(bindw);
		})
	}
</script>